tree grammar Swalker;

options {
  tokenVocab=S;
  ASTLabelType=CommonTree;
}

@header {
/**
 * Database sync parser
 * 
 * @author dzhang
 */
package org.niko.ds.parser;
}

prog	:	schema;

schema scope { String name; }
	:	^(SCHEMA ID {$schema::name=$ID.text; } table+ ) 
		{System.out.println("Define SCHEMA:"+$ID.text );};

table scope { String name; }	
	:	^(TABLE ID {$table::name=$ID.text; } column+)
		{System.out.println("Define TABLE:" + $ID.text + " IN schema " + $schema::name);};

column scope { String name; }	
	:	^(COLUMN ID {$column::name=$ID.text; } meta+ );

meta	:	info (',' info)*;

info	:	^(PROPERTY 'type' TYPE)	{System.out.println("p: type->"+$TYPE.text + "IN COLUMN:" + $column::name+ " IN table " + $table::name + " IN schema " + $schema::name);}		
		|^(PROPERTY 'size' INT) {System.out.println("p: size->"+$INT.text + "IN COLUMN:" + $column::name+ " IN table " + $table::name + " IN schema " + $schema::name);}
		|^(PROPERTY 'notnull' b1=BOOLEAN_LITERAL)	{System.out.println("p: notnull->"+$b1.text + "IN COLUMN:" + $column::name + " IN table " + $table::name + " IN schema " + $schema::name);}
		|^(PROPERTY 'pk' b2=BOOLEAN_LITERAL) {System.out.println("p: pk->"+$b2.text + "IN COLUMN:" + $column::name + " IN table " + $table::name + " IN schema " + $schema::name);};